<?php
class friendsModel extends baseModel{
    protected $table = 'user_friends';

	//获取列表
    public function friends_list($limit,$uid)
    {
        $sql="
        SELECT A.*,B.* 
        FROM {$this->model->pre}user_friends A 
        JOIN {$this->model->pre}user B ON A.fid = B.uid
        WHERE A.uid={$uid}
        LIMIT {$limit} 
        ";
        return $this->model->query($sql); 
    }

    //获取总数
    public function count($uid)
    {
        $sql="
        SELECT count(*) as num
        FROM {$this->model->pre}user_friends A 
        LEFT JOIN {$this->model->pre}user B ON A.fid = B.uid
        WHERE A.uid={$uid}
        ";
        $data=$this->model->query($sql);
        return $data[0]['num'];
    }

    //获取信息
    public function info($uid,$fid)
    {
        return $this->find('uid='.$uid.' AND fid='.$fid);

    }

    //添加
    public function add($data)
    {
         $data['remark']=text_in($data['remark']);
        return $this->insert($data);
    }

    //修改备注
    public function edit($data)
    {
        $data['remark']=text_in($data['remark']);
        return $this->update('uid='.$data['uid'].' AND fid='.$data['fid'],$data);
    }

    public function del($uid,$fid) {
        return $this->delete('uid='.$uid.' AND fid='.$fid);

    }



}